package com.zh.webflux.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zh.webflux.dao.UserInfoMapper;
import com.zh.webflux.model.UserInfo;

import io.shardingjdbc.core.api.HintManager;
import io.shardingjdbc.core.hint.HintManagerHolder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class DemoService {
	@Resource
	UserInfoMapper userInfoMapper;

	public static Long userId = 150L;

	public void demo() {
		System.out.println("Insert--------------");

		for (int i = 1; i <= 10; i++) {
			UserInfo userInfo = new UserInfo();
			userInfo.setUserId(userId);
			userInfo.setAccount("Account" + i);
			userInfo.setPassword("pass" + i);
			userInfo.setUserName("name" + i);
			userId++;
			// if (i == 3) {
			// HintManagerHolder.clear();
			// HintManager hintManager = HintManager.getInstance();
			// hintManager.addDatabaseShardingValue("user_info", "user_id", 3L);
			// hintManager.addTableShardingValue("user_info", "user_id", 3L);
			// System.out.println(userId);
			// }
			userInfoMapper.insertData(userInfo);
			//

			//

		}
		System.out.println("over..........");
	}

	public List<UserInfo> queryAllInfo() {
		return userInfoMapper.queryAllInfo();
	}

	public boolean insertData(UserInfo userInfo) {
		int s = userInfoMapper.insertData(userInfo);
		return s > 0 ? true : false;
	}

}
